package com.leetcode.partition8;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/8/8 9:08
 */
public class LC746使用最小花费爬楼梯 {

    public static int minCostClimbingStairs(int[] cost) {
        return dynamicProgramming(cost);
    }

    public static void main(String[] args) {
//        int[] cost = {10, 15, 20};
        int[] cost = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        System.out.println(minCostClimbingStairs(cost));
    }

    public static int dynamicProgramming(int[] cost) {
        int[] dp = new int[cost.length];
        dp[0] = cost[0];
        dp[1] = cost[1];
        for (int i = 2; i < cost.length; i++) {
            dp[i] = Math.min(dp[i - 2], dp[i - 1]) + cost[i];
        }
        System.out.println(Arrays.toString(dp));
        return Math.min(dp[dp.length - 1], dp[dp.length - 2]);
    }
}
